<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name="theme-color" content="#222">

<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">






  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6f697dad.js","daovoice")
  daovoice('init', {
      app_id: "6f697dad"
    });
  daovoice('update');
  </script>















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="带你学会Java基础课程,">





  <link rel="alternate" href="/atom.xml" title="达叔小生" type="application/atom+xml">






<meta name="description" content="第83节:Java中的学生管理系统分页功能">
<meta name="keywords" content="带你学会Java基础课程">
<meta property="og:type" content="article">
<meta property="og:title" content="第83节：Java中的学生管理系统分页功能">
<meta property="og:url" content="https://huangguangda.github.io/2019/02/02/1/index.html">
<meta property="og:site_name" content="达叔小生">
<meta property="og:description" content="第83节:Java中的学生管理系统分页功能">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-3f72290b57669942.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-64c2469aeae3f623.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-3e162ff3b074f227.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-b9376d6f0dcf42ae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-0c5cae205b53236a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-890560404dbaa0f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-0f55c2f1e5602f81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-f9bcb7cfdae96cd0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-f91be865fb8a8f96.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/11158618-a77a8b8e2cca3311.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2019-02-05T16:21:26.941Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="第83节：Java中的学生管理系统分页功能">
<meta name="twitter:description" content="第83节:Java中的学生管理系统分页功能">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/11158618-3f72290b57669942.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://huangguangda.github.io/2019/02/02/1/">




<!-- 网页加载条 -->
<script src="https://neveryu.github.io/js/src/pace.min.js"></script>
  <title>第83节：Java中的学生管理系统分页功能 | 达叔小生</title>
  









  <!-- 音频播放 -->
<link rel="stylesheet" href="/dist/APlayer.min.css">
<div id="aplayer"></div>
<script type="text/javascript" src="/dist/APlayer.min.js"></script>
<script type="text/javascript" src="/dist/music.js"></script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <a href="https://github.com/huangguangda" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">达叔小生</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">爱好分享的码农</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-书籍">
          <a href="/books" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br>
            
            书籍
          </a>
        </li>
      
        
        <li class="menu-item menu-item-电影">
          <a href="/movies" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-chrome"></i> <br>
            
            电影
          </a>
        </li>
      
        
        <li class="menu-item menu-item-站点">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            站点
          </a>
        </li>
      
        
        <li class="menu-item menu-item-公益">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益
          </a>
        </li>
      
        
        <li class="menu-item menu-item-课本">
          <a href="/book/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-apple"></i> <br>
            
            课本
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>


 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://huangguangda.github.io/2019/02/02/1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="达叔小生">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="达叔小生">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">第83节：Java中的学生管理系统分页功能</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-02T00:17:21+08:00">
                2019-02-02
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/带你学会Java基础课程/" itemprop="url" rel="index">
                    <span itemprop="name">带你学会Java基础课程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  8,052
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  45
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="https://upload-images.jianshu.io/upload_images/11158618-3f72290b57669942.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="标题图"></p>
<blockquote>
<p>第83节:Java中的学生管理系统分页功能</p>
</blockquote>
<a id="more"></a>
<p>分页功能一般可以做成两种，一种是物理分页，另一种是逻辑分页。这两种功能是有各自的特点的，物理分页是查询的时候，对数据库进行访问，只是查一页数据就进行返回，其特点是对内存中数据量存储不大，只是缺点就是要对数据库不断的进行访问；而对逻辑分页来说，就有所不同，它是一下子就把所有的数据全部查询出来，然后放入到内存中，访问速度快，缺点就是对内存空间不足，数据量过大。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from stu limit 5;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-64c2469aeae3f623.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// offset 偏移前面的多少条，offset 1 跳过前面的一条</span><br><span class="line">select * from stu limit 5 offset 5;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-3e162ff3b074f227.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM stu LIMIT 5 , 5;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-b9376d6f0dcf42ae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM stu LIMIT 5 , 2;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM stu LIMIT 2 , 5;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-0c5cae205b53236a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<blockquote>
<p>写分页的dao模式</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// index.jsp</span><br><span class="line">&lt;h3&gt;&lt;a href=&quot;StudentListPageServlet?currentPage=1&quot;&gt;分页显示所有学生&lt;/a&gt;&lt;/h3&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">// StudentListPageServlet</span><br><span class="line">//1. 获取需要显示的页码数</span><br><span class="line">int currentPage =Integer.parseInt( request.getParameter(&quot;currentPage&quot;));</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// StudentDao</span><br><span class="line">// 接口中定义的成员都是常量</span><br><span class="line">// 一页显示多少条记录</span><br><span class="line">int PAGE_SIZE = 5;</span><br><span class="line">// 分页dao,查询当页的学生数据</span><br><span class="line">List&lt;Student&gt; findStudentByPage(int currentPage) throws SQLException;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-890560404dbaa0f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// StudentDaoImpl</span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findStudentByPage(int currentPage) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		// 第一个问号，一页返回多少条记录，第二个问号，跳过前面的多少条记录</span><br><span class="line">		//5 0 --- 第一页 (1-1)*5</span><br><span class="line">		//5 5  --- 第二页 (2-1)*5</span><br><span class="line">		//5 10  --- 第三页</span><br><span class="line">		return runner.query(&quot;select * from stu limit ? offset ?&quot;, new BeanListHandler&lt;Student&gt;(Student.class),PAGE_SIZE , (currentPage-1)*PAGE_SIZE);</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>业务逻辑</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select count(*) from stu;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-0f55c2f1e5602f81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<blockquote>
<p>业务逻辑</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 这是用于分页显示学生列表的servlet</span><br><span class="line"> */</span><br><span class="line">public class StudentListPageServlet extends HttpServlet &#123;</span><br><span class="line">	</span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			//1. 获取需要显示的页码数</span><br><span class="line">			int currentPage =Integer.parseInt( request.getParameter(&quot;currentPage&quot;));</span><br><span class="line">			</span><br><span class="line">			//2. 根据指定的页数，去获取该页的数据回来</span><br><span class="line">			//List&lt;Student&gt; --- list.jsp</span><br><span class="line">			</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			PageBean pageBean= service.findStudentByPage(currentPage);</span><br><span class="line">			request.setAttribute(&quot;pageBean&quot;, pageBean);</span><br><span class="line">			//3. 跳转界面。</span><br><span class="line">			request.getRequestDispatcher(&quot;list_page.jsp&quot;).forward(request, response);</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>去业务逻辑去找</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.service;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生的业务处理规范</span><br><span class="line"> * */</span><br><span class="line">public interface StudentService &#123;</span><br><span class="line">	// 分页dao,查询当页的学生数据</span><br><span class="line">	// 分页的很多小逻辑业务 可以做到service里面</span><br><span class="line">	// 业务做到service里面，做的就是bean了，当前页，总页数，显示条数， 总记录数</span><br><span class="line">	// 返回的是一个bean了</span><br><span class="line">	// 返回的是PageBean里面的所有数据了</span><br><span class="line">	PageBean findStudentByPage(int currentPage) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据姓名或性别，查询</span><br><span class="line">	List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException;</span><br><span class="line"></span><br><span class="line">	/*</span><br><span class="line">	 * 查询所有学生 list&lt;Student&gt;</span><br><span class="line">	 */</span><br><span class="line">	List&lt;Student&gt; findAll() throws SQLException;</span><br><span class="line"></span><br><span class="line">	void insert(Student student) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// sid根据id删除学生</span><br><span class="line">	void delete(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据id查询单个学生对象</span><br><span class="line">	Student findStudentById(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 更新学生信息</span><br><span class="line">	void update(Student student) throws SQLException;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.service.impl;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.dao.StudentDao;</span><br><span class="line">import com.dashucoding.dao.impl.StudentDaoImpl;</span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生业务实现</span><br><span class="line"> * */</span><br><span class="line">public class StudentServiceImpl implements StudentService &#123;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findAll() throws SQLException &#123;</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findAll();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void insert(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.insert(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void delete(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.delete(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public Student findStudentById(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findStudentById(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void update(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.update(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.searchStudent(sname, sgender);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public PageBean findStudentByPage(int currentPage) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		// 封装分页的该页的数据</span><br><span class="line">		PageBean&lt;Student&gt; pageBean = new PageBean&lt;Student&gt;();</span><br><span class="line">		</span><br><span class="line">		int pageSize = StudentDao.PAGE_SIZE;</span><br><span class="line">		</span><br><span class="line">		// 设置当前页</span><br><span class="line">		pageBean.setCurrentPage(currentPage);</span><br><span class="line">		// 每条记录</span><br><span class="line">		pageBean.setPageSize(pageSize);</span><br><span class="line">		</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		List&lt;Student&gt; list = dao.findStudentByPage(currentPage);</span><br><span class="line">		pageBean.setList(list);</span><br><span class="line">		// 总记录数，总页数</span><br><span class="line">		int count = dao.findCount();</span><br><span class="line">		pageBean.setTotalSize(count);</span><br><span class="line">		</span><br><span class="line">		// 总页数</span><br><span class="line">		pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1);</span><br><span class="line">		</span><br><span class="line">		return null;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">// 封装的数据</span><br><span class="line">package com.dashucoding.domain;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">// 一个用于封装了分页的数据</span><br><span class="line">// 有： 当前学生集合数据，总的记录数，总的页数，当前页，每页的显示记录数</span><br><span class="line">public class PageBean&lt;T&gt; &#123;</span><br><span class="line"></span><br><span class="line">	private int currentPage; // 当前页</span><br><span class="line">	private int totalPage;// 总页数</span><br><span class="line">	private int pageSize;// 每页的记录数，每页要显示多少记录</span><br><span class="line">	private int totalSize; // 总的记录数</span><br><span class="line">	private List&lt;T&gt; list; // 当前页的学生集合</span><br><span class="line">	</span><br><span class="line">	public int getCurrentPage() &#123;</span><br><span class="line">		return currentPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setCurrentPage(int currentPage) &#123;</span><br><span class="line">		this.currentPage = currentPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getTotalPage() &#123;</span><br><span class="line">		return totalPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setTotalPage(int totalPage) &#123;</span><br><span class="line">		this.totalPage = totalPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getPageSize() &#123;</span><br><span class="line">		return pageSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setPageSize(int pageSize) &#123;</span><br><span class="line">		this.pageSize = pageSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getTotalSize() &#123;</span><br><span class="line">		return totalSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setTotalSize(int totalSize) &#123;</span><br><span class="line">		this.totalSize = totalSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public List&lt;T&gt; getList() &#123;</span><br><span class="line">		return list;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setList(List&lt;T&gt; list) &#123;</span><br><span class="line">		this.list = list;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-f9bcb7cfdae96cd0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<blockquote>
<p>最后就靠显示页面逻辑</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">    </span><br><span class="line"> &lt;%@ taglib prefix=&quot;c&quot;  uri=&quot;http://java.sun.com/jsp/jstl/core&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;学生列表页面&lt;/title&gt;</span><br><span class="line"></span><br><span class="line">&lt;script type=&quot;text/javascript&quot;&gt;</span><br><span class="line"></span><br><span class="line">	function doDelete(sid) &#123;</span><br><span class="line">		/* 如果这里弹出的对话框，用户点击的是确定，就马上去请求Servlet。 </span><br><span class="line">		如何知道用户点击的是确定。</span><br><span class="line">		如何在js的方法中请求servlet。 */</span><br><span class="line">		var flag = confirm(&quot;是否确定删除?&quot;);</span><br><span class="line">		if(flag)&#123;</span><br><span class="line">			//表明点了确定。 访问servlet。 在当前标签页上打开 超链接，</span><br><span class="line">			//window.location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">			location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">	&lt;form action=&quot;SearchStudentServlet&quot; method=&quot;post&quot;&gt;</span><br><span class="line">		&lt;table border=&quot;1&quot; width=&quot;700&quot;&gt;</span><br><span class="line">		</span><br><span class="line">			&lt;tr &gt;</span><br><span class="line">				&lt;td colspan=&quot;8&quot;&gt;</span><br><span class="line">					</span><br><span class="line">					按姓名查询:&lt;input type=&quot;text&quot; name=&quot;sname&quot;/&gt;</span><br><span class="line">					&amp;nbsp;</span><br><span class="line">					按性别查询:&lt;select name=&quot;sgender&quot;&gt;</span><br><span class="line">								&lt;option value=&quot;&quot;&gt;--请选择--</span><br><span class="line">								&lt;option value=&quot;男&quot;&gt;男</span><br><span class="line">								&lt;option value=&quot;女&quot;&gt;女</span><br><span class="line">							  &lt;/select&gt;</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">					&lt;input type=&quot;submit&quot; value=&quot;查询&quot;&gt;</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">					&lt;a href=&quot;add.jsp&quot;&gt;添加&lt;/a&gt;</span><br><span class="line">				&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">		</span><br><span class="line">		  &lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">			&lt;td&gt;编号&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;姓名&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;性别&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;电话&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;生日&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;爱好&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;简介&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;操作&lt;/td&gt;</span><br><span class="line">		  &lt;/tr&gt;</span><br><span class="line">		  </span><br><span class="line">			  &lt;c:forEach items=&quot;$&#123;pageBean.list &#125;&quot; var=&quot;stu&quot;&gt;</span><br><span class="line">				  &lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sid &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sname &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.gender &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.phone &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.birthday &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.hobby &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.info &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;&lt;a href=&quot;EditServlet?sid=$&#123;stu.sid &#125;&quot;&gt;更新&lt;/a&gt;   &lt;a href=&quot;#&quot; onclick=&quot;doDelete($&#123;stu.sid&#125;)&quot;&gt;删除&lt;/a&gt;&lt;/td&gt;</span><br><span class="line">				  &lt;/tr&gt;</span><br><span class="line">			  &lt;/c:forEach&gt;</span><br><span class="line">			  </span><br><span class="line">			  &lt;tr&gt;</span><br><span class="line">			  	&lt;td colspan=&quot;8&quot;&gt;</span><br><span class="line">			  		第 $&#123;pageBean.currentPage &#125; / $&#123;pageBean.totalPage &#125;</span><br><span class="line">			  		&amp;nbsp;&amp;nbsp;</span><br><span class="line">			  		每页显示$&#123;pageBean.pageSize &#125;条  &amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">			  		总的记录数$&#123;pageBean.totalSize &#125; &amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">			  		</span><br><span class="line">			  		&lt;c:if test=&quot;$&#123;pageBean.currentPage !=1 &#125;&quot;&gt;</span><br><span class="line">			  			&lt;a href=&quot;StudentListPageServlet?currentPage=1&quot;&gt;首页&lt;/a&gt;</span><br><span class="line">						| &lt;a href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.currentPage-1 &#125;&quot;&gt;上一页&lt;/a&gt;</span><br><span class="line">			  		&lt;/c:if&gt;</span><br><span class="line">			  		</span><br><span class="line">			  		&lt;c:forEach begin=&quot;1&quot; end=&quot;$&#123;pageBean.totalPage &#125;&quot; var=&quot;i&quot;&gt;</span><br><span class="line">			  			&lt;c:if test=&quot;$&#123;pageBean.currentPage == i &#125;&quot;&gt;</span><br><span class="line">			  				$&#123;i &#125;</span><br><span class="line">			  			&lt;/c:if&gt;</span><br><span class="line">			  			&lt;c:if test=&quot;$&#123;pageBean.currentPage != i &#125;&quot;&gt;</span><br><span class="line">			  				&lt;a href=&quot;StudentListPageServlet?currentPage=$&#123;i &#125;&quot;&gt;$&#123;i &#125;&lt;/a&gt;</span><br><span class="line">			  			&lt;/c:if&gt;</span><br><span class="line">			  		</span><br><span class="line">			  		&lt;/c:forEach&gt;</span><br><span class="line">			  		</span><br><span class="line">			  		</span><br><span class="line">			  		&lt;c:if test=&quot;$&#123;pageBean.currentPage !=pageBean.totalPage &#125;&quot;&gt;</span><br><span class="line">			  			&lt;a href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.currentPage+1 &#125;&quot;&gt;下一页&lt;/a&gt; | </span><br><span class="line">			  			&lt;a href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.totalPage &#125;&quot;&gt;尾页&lt;/a&gt;</span><br><span class="line">			  		&lt;/c:if&gt;</span><br><span class="line">			  	&lt;/td&gt;</span><br><span class="line">			  &lt;/tr&gt;</span><br><span class="line">		  &lt;/table&gt;</span><br><span class="line">	  &lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-f91be865fb8a8f96.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="项目结构"></p>
<blockquote>
<p>我的源码</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.dao;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是针对学生表的数据访问</span><br><span class="line"> * </span><br><span class="line"> * */</span><br><span class="line">public interface StudentDao &#123;</span><br><span class="line">	// 接口中定义的成员都是常量</span><br><span class="line">	// 一页显示多少条记录</span><br><span class="line">	int PAGE_SIZE = 5;</span><br><span class="line">	// 分页dao,查询当页的学生数据</span><br><span class="line">	List&lt;Student&gt; findStudentByPage(int currentPage) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据姓名或性别，查询</span><br><span class="line">	List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException;</span><br><span class="line"></span><br><span class="line">	/*</span><br><span class="line">	 * 查询所有学生 list&lt;Student&gt;</span><br><span class="line">	 */</span><br><span class="line">	List&lt;Student&gt; findAll() throws SQLException;</span><br><span class="line"></span><br><span class="line">	void insert(Student student) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// sid根据id删除学生</span><br><span class="line">	void delete(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据id查询单个学生对象</span><br><span class="line">	Student findStudentById(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 更新学生信息</span><br><span class="line">	void update(Student student) throws SQLException;</span><br><span class="line">	</span><br><span class="line">	// 查询总的学生记录数</span><br><span class="line">	int findCount() throws SQLException;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.dao.impl;</span><br><span class="line"></span><br><span class="line">import java.sql.Connection;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import org.apache.commons.dbutils.QueryRunner;</span><br><span class="line">import org.apache.commons.dbutils.handlers.BeanHandler;</span><br><span class="line">import org.apache.commons.dbutils.handlers.BeanListHandler;</span><br><span class="line">import org.apache.commons.dbutils.handlers.ScalarHandler;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.dao.StudentDao;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.util.JDBCUtil02;</span><br><span class="line">import com.dashucoding.util.TextUtils;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> *这是StudentDao的实现,针对前面定义的规范,做出具体的实现</span><br><span class="line"> * */</span><br><span class="line">public class StudentDaoImpl implements StudentDao &#123;</span><br><span class="line">	/*</span><br><span class="line">	 * 查询所有学生</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findAll() throws SQLException &#123;</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		return runner.query(&quot;select * from stu&quot;, new BeanListHandler&lt;Student&gt;(Student.class));</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void insert(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		runner.update(&quot;insert into stu values(null, ?,?,?,?,?,?)&quot;, </span><br><span class="line">				student.getSname(), </span><br><span class="line">				student.getGender(),</span><br><span class="line">				student.getPhone(), </span><br><span class="line">				student.getBirthday(), </span><br><span class="line">				student.getHobby(), </span><br><span class="line">				student.getInfo()</span><br><span class="line">				);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void delete(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line"></span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		runner.update(&quot;delete from stu where sid=?&quot;, sid);</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public Student findStudentById(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		</span><br><span class="line">		return runner.query(&quot;select * from stu where sid = ?&quot;, new BeanHandler&lt;Student&gt;(Student.class), sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void update(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		runner.update(&quot;update stu set sname=?, gender=?, phone=?, birthday=?, hobby=?, info=? where sid=?&quot;,</span><br><span class="line">				student.getSname(), </span><br><span class="line">				student.getGender(),</span><br><span class="line">				student.getPhone(), </span><br><span class="line">				student.getBirthday(), </span><br><span class="line">				student.getHobby(), </span><br><span class="line">				student.getInfo(),</span><br><span class="line">				student.getSid());</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// 模糊查询</span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		</span><br><span class="line">		/*System.out.println(sname + sgender);*/</span><br><span class="line">		</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		</span><br><span class="line">		/*</span><br><span class="line">		 * String sql = &quot;select * from stu where sname=? or sgender=?&quot;;</span><br><span class="line">		 * select * from stu where sname like ?;</span><br><span class="line">		 * select * from stu where gender = ?;</span><br><span class="line">		 * select * from stu where sname like ? and gender = ?;</span><br><span class="line">		 * 如果两个都没有就查询所有</span><br><span class="line">		 * sql = &quot;select * from stu&quot;</span><br><span class="line">		 * if(姓名)&#123;</span><br><span class="line">		 *  sql = sql + &quot;where sname like ?&quot;;</span><br><span class="line">		 * &#125;</span><br><span class="line">		 * if(性别)&#123;</span><br><span class="line">		 *  sql = sql + &quot;where gender = ?&quot;;</span><br><span class="line">		 * &#125;</span><br><span class="line">		 * </span><br><span class="line">		 * String sql = &quot;select * from stu where 1=1&quot;;</span><br><span class="line">		 * if(姓名)&#123;</span><br><span class="line">		 *  sql = sql + &quot; and sname like ? &quot;;</span><br><span class="line">		 * &#125;</span><br><span class="line">		 * if(性别)&#123;</span><br><span class="line">		 *  sql = sql + &quot; and gender = ? &quot;;</span><br><span class="line">		 * &#125;</span><br><span class="line">		 * */</span><br><span class="line">		</span><br><span class="line">		String sql = &quot;select * from stu where 1=1&quot;;</span><br><span class="line">		</span><br><span class="line">		List&lt;String&gt; list = new ArrayList&lt;String&gt;();</span><br><span class="line">		</span><br><span class="line">		if(!TextUtils.isEmpty(sname)) &#123;</span><br><span class="line">			sql = sql + &quot; and sname like ? &quot;;</span><br><span class="line">			list.add(&quot;%&quot;+sname+&quot;%&quot;);</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		if(!TextUtils.isEmpty(sgender)) &#123;</span><br><span class="line">			sql = sql + &quot; and gender = ? &quot;;</span><br><span class="line">			list.add(sgender);</span><br><span class="line">		&#125;</span><br><span class="line">		/*list.toArray()*/</span><br><span class="line">		</span><br><span class="line">		return runner.query(sql, new BeanListHandler&lt;Student&gt;(Student.class),list.toArray());</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findStudentByPage(int currentPage) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		// 第一个问号，一页返回多少条记录，第二个问号，跳过前面的多少条记录</span><br><span class="line">		//5 0 --- 第一页 (1-1)*5</span><br><span class="line">		//5 5  --- 第二页 (2-1)*5</span><br><span class="line">		//5 10  --- 第三页</span><br><span class="line">		return runner.query(&quot;select * from stu limit ? offset ?&quot;, new BeanListHandler&lt;Student&gt;(Student.class),PAGE_SIZE , (currentPage-1)*PAGE_SIZE);</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// 查询总的记录数</span><br><span class="line">	@Override</span><br><span class="line">	public int findCount() throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		QueryRunner runner = new QueryRunner(JDBCUtil02.getDataSource());</span><br><span class="line">		// 用于处理平均值，总的个数</span><br><span class="line">		Long result = (Long) runner.query(&quot;select count(*) from stu&quot;, new ScalarHandler());</span><br><span class="line">		return result.intValue();</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.domain;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">// 一个用于封装了分页的数据</span><br><span class="line">// 有： 当前学生集合数据，总的记录数，总的页数，当前页，每页的显示记录数</span><br><span class="line">public class PageBean&lt;T&gt; &#123;</span><br><span class="line"></span><br><span class="line">	private int currentPage; // 当前页</span><br><span class="line">	private int totalPage;// 总页数</span><br><span class="line">	private int pageSize;// 每页的记录数，每页要显示多少记录</span><br><span class="line">	private int totalSize; // 总的记录数</span><br><span class="line">	private List&lt;T&gt; list; // 当前页的学生集合</span><br><span class="line">	</span><br><span class="line">	public int getCurrentPage() &#123;</span><br><span class="line">		return currentPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setCurrentPage(int currentPage) &#123;</span><br><span class="line">		this.currentPage = currentPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getTotalPage() &#123;</span><br><span class="line">		return totalPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setTotalPage(int totalPage) &#123;</span><br><span class="line">		this.totalPage = totalPage;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getPageSize() &#123;</span><br><span class="line">		return pageSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setPageSize(int pageSize) &#123;</span><br><span class="line">		this.pageSize = pageSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public int getTotalSize() &#123;</span><br><span class="line">		return totalSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setTotalSize(int totalSize) &#123;</span><br><span class="line">		this.totalSize = totalSize;</span><br><span class="line">	&#125;</span><br><span class="line">	public List&lt;T&gt; getList() &#123;</span><br><span class="line">		return list;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setList(List&lt;T&gt; list) &#123;</span><br><span class="line">		this.list = list;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.domain;</span><br><span class="line"></span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生封装的对象bean</span><br><span class="line"> * </span><br><span class="line"> * */</span><br><span class="line">public class Student &#123;</span><br><span class="line">	</span><br><span class="line">	private int sid;</span><br><span class="line">	private String sname;</span><br><span class="line">	private String gender;</span><br><span class="line">	private String phone;</span><br><span class="line">	private String hobby;</span><br><span class="line">	private String info;</span><br><span class="line">	private Date birthday;</span><br><span class="line">	</span><br><span class="line">	public Student() &#123;</span><br><span class="line">		super();</span><br><span class="line">		// TODO Auto-generated constructor stub</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Student(int sid, String sname, String gender, String phone, String hobby, String info, Date birthday) &#123;</span><br><span class="line">		super();</span><br><span class="line">		this.sid = sid;</span><br><span class="line">		this.sname = sname;</span><br><span class="line">		this.gender = gender;</span><br><span class="line">		this.phone = phone;</span><br><span class="line">		this.hobby = hobby;</span><br><span class="line">		this.info = info;</span><br><span class="line">		this.birthday = birthday;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	public Student(String sname, String gender, String phone, String hobby, String info, Date birthday) &#123;</span><br><span class="line">		super();</span><br><span class="line">		this.sname = sname;</span><br><span class="line">		this.gender = gender;</span><br><span class="line">		this.phone = phone;</span><br><span class="line">		this.hobby = hobby;</span><br><span class="line">		this.info = info;</span><br><span class="line">		this.birthday = birthday;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public int getSid() &#123;</span><br><span class="line">		return sid;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setSid(int sid) &#123;</span><br><span class="line">		this.sid = sid;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getSname() &#123;</span><br><span class="line">		return sname;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setSname(String sname) &#123;</span><br><span class="line">		this.sname = sname;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getGender() &#123;</span><br><span class="line">		return gender;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setGender(String gender) &#123;</span><br><span class="line">		this.gender = gender;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getPhone() &#123;</span><br><span class="line">		return phone;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setPhone(String phone) &#123;</span><br><span class="line">		this.phone = phone;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getHobby() &#123;</span><br><span class="line">		return hobby;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setHobby(String hobby) &#123;</span><br><span class="line">		this.hobby = hobby;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getInfo() &#123;</span><br><span class="line">		return info;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setInfo(String info) &#123;</span><br><span class="line">		this.info = info;</span><br><span class="line">	&#125;</span><br><span class="line">	public Date getBirthday() &#123;</span><br><span class="line">		return birthday;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setBirthday(Date birthday) &#123;</span><br><span class="line">		this.birthday = birthday;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public String toString() &#123;</span><br><span class="line">		return &quot;Student [sid=&quot; + sid + &quot;, sname=&quot; + sname + &quot;, gender=&quot; + gender + &quot;, phone=&quot; + phone + &quot;, hobby=&quot;</span><br><span class="line">				+ hobby + &quot;, info=&quot; + info + &quot;, birthday=&quot; + birthday + &quot;]&quot;;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.service;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生的业务处理规范</span><br><span class="line"> * */</span><br><span class="line">public interface StudentService &#123;</span><br><span class="line">	// 分页dao,查询当页的学生数据</span><br><span class="line">	// 分页的很多小逻辑业务 可以做到service里面</span><br><span class="line">	// 业务做到service里面，做的就是bean了，当前页，总页数，显示条数， 总记录数</span><br><span class="line">	// 返回的是一个bean了</span><br><span class="line">	// 返回的是PageBean里面的所有数据了</span><br><span class="line">	PageBean findStudentByPage(int currentPage) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据姓名或性别，查询</span><br><span class="line">	List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException;</span><br><span class="line"></span><br><span class="line">	/*</span><br><span class="line">	 * 查询所有学生 list&lt;Student&gt;</span><br><span class="line">	 */</span><br><span class="line">	List&lt;Student&gt; findAll() throws SQLException;</span><br><span class="line"></span><br><span class="line">	void insert(Student student) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// sid根据id删除学生</span><br><span class="line">	void delete(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 根据id查询单个学生对象</span><br><span class="line">	Student findStudentById(int sid) throws SQLException;</span><br><span class="line"></span><br><span class="line">	// 更新学生信息</span><br><span class="line">	void update(Student student) throws SQLException;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.service.impl;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.dao.StudentDao;</span><br><span class="line">import com.dashucoding.dao.impl.StudentDaoImpl;</span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生业务实现</span><br><span class="line"> * */</span><br><span class="line">public class StudentServiceImpl implements StudentService &#123;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findAll() throws SQLException &#123;</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findAll();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void insert(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.insert(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void delete(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.delete(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public Student findStudentById(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findStudentById(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void update(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.update(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.searchStudent(sname, sgender);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public PageBean findStudentByPage(int currentPage) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		// 封装分页的该页的数据</span><br><span class="line">		PageBean&lt;Student&gt; pageBean = new PageBean&lt;Student&gt;();</span><br><span class="line">		</span><br><span class="line">		int pageSize = StudentDao.PAGE_SIZE;</span><br><span class="line">		</span><br><span class="line">		// 设置当前页</span><br><span class="line">		pageBean.setCurrentPage(currentPage);</span><br><span class="line">		// 每条记录</span><br><span class="line">		pageBean.setPageSize(pageSize);</span><br><span class="line">		</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		List&lt;Student&gt; list = dao.findStudentByPage(currentPage);</span><br><span class="line">		pageBean.setList(list);</span><br><span class="line">		// 总记录数，总页数</span><br><span class="line">		int count = dao.findCount();</span><br><span class="line">		pageBean.setTotalSize(count);</span><br><span class="line">		</span><br><span class="line">		// 总页数</span><br><span class="line">		pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1);</span><br><span class="line">		</span><br><span class="line">		return null;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.text.SimpleDateFormat;</span><br><span class="line">import java.util.Arrays;</span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 用于处理学生的添加请求</span><br><span class="line"> */</span><br><span class="line">public class AddServlet extends HttpServlet &#123;</span><br><span class="line"></span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		request.setCharacterEncoding(&quot;UTF-8&quot;);</span><br><span class="line"></span><br><span class="line">		try &#123;</span><br><span class="line"></span><br><span class="line">			// 1. 获取客户端提交上来的数据</span><br><span class="line">			String sname = request.getParameter(&quot;sname&quot;);</span><br><span class="line">			String gender = request.getParameter(&quot;gender&quot;);</span><br><span class="line">			String phone = request.getParameter(&quot;phone&quot;);</span><br><span class="line">			String birthday = request.getParameter(&quot;birthday&quot;);</span><br><span class="line">			String info = request.getParameter(&quot;info&quot;);</span><br><span class="line">			// String hobby = request.getParameter(&quot;hobby&quot;);//hobby : 游泳，写字， 足球。</span><br><span class="line">			String[] h = request.getParameterValues(&quot;hobby&quot;);</span><br><span class="line"></span><br><span class="line">			String hobby = Arrays.toString(h);</span><br><span class="line">			hobby = hobby.substring(1, hobby.length() - 1);</span><br><span class="line"></span><br><span class="line">			// 2. 添加到数据库</span><br><span class="line">			// string -- date</span><br><span class="line">			Date date = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;).parse(birthday);</span><br><span class="line"></span><br><span class="line">			Student student = new Student(sname, gender, phone, hobby, info, date);</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			service.insert(student);</span><br><span class="line"></span><br><span class="line">			// 3. 跳转到列表页</span><br><span class="line">			request.getRequestDispatcher(&quot;StudentListServlet&quot;).forward(request, response);</span><br><span class="line"></span><br><span class="line">		&#125; catch (Exception e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 用于处理删除学生</span><br><span class="line"> */</span><br><span class="line">public class DeleteServlet extends HttpServlet &#123;</span><br><span class="line"></span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			int sid = Integer.parseInt(request.getParameter(&quot;sid&quot;));</span><br><span class="line">			// System.out.println(&quot;sid=&quot;+sid);</span><br><span class="line">			// 执行删除</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			service.delete(sid);</span><br><span class="line">			// 跳转到列表页</span><br><span class="line">			request.getRequestDispatcher(&quot;StudentListServlet&quot;).forward(request, response);</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			// TODO Auto-generated catch block</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 处理单个学生的更新，查询学生的信息，跳转到更新的页面</span><br><span class="line"> */</span><br><span class="line">public class EditServlet extends HttpServlet &#123;</span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			// 接收id</span><br><span class="line">			int sid = Integer.parseInt(request.getParameter(&quot;sid&quot;));</span><br><span class="line">			// 查询学生数据</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			Student stu = service.findStudentById(sid);</span><br><span class="line"></span><br><span class="line">			// 显示数据</span><br><span class="line">			// 存储数据</span><br><span class="line">			request.setAttribute(&quot;stu&quot;, stu);</span><br><span class="line">			// 跳转</span><br><span class="line">			request.getRequestDispatcher(&quot;edit.jsp&quot;).forward(request, response);</span><br><span class="line"></span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			// TODO Auto-generated catch block</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse</span><br><span class="line">	 *      response)</span><br><span class="line">	 */</span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Servlet implementation class SearchStudentServlet</span><br><span class="line"> */</span><br><span class="line">public class SearchStudentServlet extends HttpServlet &#123;</span><br><span class="line"></span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		request.setCharacterEncoding(&quot;UTF-8&quot;);</span><br><span class="line">		try &#123;</span><br><span class="line">			// 取到了要查询的关键数据</span><br><span class="line">			String sname = request.getParameter(&quot;sname&quot;);</span><br><span class="line">			String sgender = request.getParameter(&quot;sgender&quot;);</span><br><span class="line"></span><br><span class="line">			// 找service查询</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			List&lt;Student&gt; list = service.searchStudent(sname, sgender);</span><br><span class="line">			</span><br><span class="line">			/*for(Student student : list) &#123;</span><br><span class="line">				System.out.println(&quot;stu=&quot; + student);</span><br><span class="line">			&#125;*/</span><br><span class="line">			</span><br><span class="line">			request.setAttribute(&quot;list&quot;, list);</span><br><span class="line">			// 跳转界面</span><br><span class="line">			request.getRequestDispatcher(&quot;list.jsp&quot;).forward(request, response);</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			// TODO Auto-generated catch block</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 这是用于分页显示学生列表的servlet</span><br><span class="line"> */</span><br><span class="line">public class StudentListPageServlet extends HttpServlet &#123;</span><br><span class="line">	</span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			//1. 获取需要显示的页码数</span><br><span class="line">			int currentPage =Integer.parseInt( request.getParameter(&quot;currentPage&quot;));</span><br><span class="line">			</span><br><span class="line">			//2. 根据指定的页数，去获取该页的数据回来</span><br><span class="line">			//List&lt;Student&gt; --- list.jsp</span><br><span class="line">			</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			PageBean pageBean= service.findStudentByPage(currentPage);</span><br><span class="line">			request.setAttribute(&quot;pageBean&quot;, pageBean);</span><br><span class="line">			//3. 跳转界面。</span><br><span class="line">			request.getRequestDispatcher(&quot;list_page.jsp&quot;).forward(request, response);</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.dao.StudentDao;</span><br><span class="line">import com.dashucoding.dao.impl.StudentDaoImpl;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">public class StudentListServlet extends HttpServlet &#123;</span><br><span class="line"></span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			// 查询所有的学生</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			List&lt;Student&gt; list = service.findAll();</span><br><span class="line">			// 把数据存储到作用域中</span><br><span class="line">			request.setAttribute(&quot;list&quot;, list);</span><br><span class="line">			</span><br><span class="line">			// 跳转页面</span><br><span class="line">			request.getRequestDispatcher(&quot;list.jsp&quot;).forward(request,response);</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			// TODO Auto-generated catch block</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.servlet;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.text.SimpleDateFormat;</span><br><span class="line">import java.util.Arrays;</span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line">import com.dashucoding.service.impl.StudentServiceImpl;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Servlet implementation class UpdateServlet</span><br><span class="line"> */</span><br><span class="line">public class UpdateServlet extends HttpServlet &#123;</span><br><span class="line"></span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		request.setCharacterEncoding(&quot;UTF-8&quot;);</span><br><span class="line">		try &#123;</span><br><span class="line">			// 1. 获取客户端提交上来的数据</span><br><span class="line">			int sid = Integer.parseInt(request.getParameter(&quot;sid&quot;));</span><br><span class="line">			String sname = request.getParameter(&quot;sname&quot;);</span><br><span class="line">			String gender = request.getParameter(&quot;gender&quot;);</span><br><span class="line">			String phone = request.getParameter(&quot;phone&quot;);</span><br><span class="line">			String birthday = request.getParameter(&quot;birthday&quot;); </span><br><span class="line">			String info = request.getParameter(&quot;info&quot;);</span><br><span class="line">			// String hobby = request.getParameter(&quot;hobby&quot;);</span><br><span class="line">			String[] h = request.getParameterValues(&quot;hobby&quot;);</span><br><span class="line"></span><br><span class="line">			String hobby = Arrays.toString(h);</span><br><span class="line">			hobby = hobby.substring(1, hobby.length() - 1);</span><br><span class="line">			// 2. 添加到数据库</span><br><span class="line"></span><br><span class="line">			Date date = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;).parse(birthday);</span><br><span class="line">			Student student = new Student(sid, sname, gender, phone, hobby, info, date);</span><br><span class="line"></span><br><span class="line">			// 2. 更新数据库数据</span><br><span class="line">			StudentService service = new StudentServiceImpl();</span><br><span class="line">			service.update(student);</span><br><span class="line"></span><br><span class="line">			// 3. 跳转界面</span><br><span class="line">			request.getRequestDispatcher(&quot;StudentListServlet&quot;).forward(request, response);</span><br><span class="line">		&#125; catch (Exception e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">			throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.util;</span><br><span class="line"></span><br><span class="line">import java.io.FileInputStream;</span><br><span class="line">import java.io.InputStream;</span><br><span class="line">import java.sql.Connection;</span><br><span class="line">import java.sql.DriverManager;</span><br><span class="line">import java.sql.ResultSet;</span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.sql.Statement;</span><br><span class="line">import java.util.Properties;</span><br><span class="line"></span><br><span class="line">import javax.sql.DataSource;</span><br><span class="line"></span><br><span class="line">import com.mchange.v2.c3p0.ComboPooledDataSource;</span><br><span class="line"></span><br><span class="line">public class JDBCUtil02 &#123;</span><br><span class="line">	</span><br><span class="line">	static ComboPooledDataSource dataSource = null;</span><br><span class="line"></span><br><span class="line">	static &#123;</span><br><span class="line">		dataSource = new ComboPooledDataSource();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	public static DataSource getDataSource() &#123;</span><br><span class="line">		return dataSource;</span><br><span class="line">	&#125;</span><br><span class="line">	/**</span><br><span class="line">	 * 获取连接对象</span><br><span class="line">	 * @return</span><br><span class="line">	 * @throws SQLException </span><br><span class="line">	 */</span><br><span class="line">	public static Connection getConn() throws SQLException&#123;</span><br><span class="line">		</span><br><span class="line">		return dataSource.getConnection();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 释放资源</span><br><span class="line">	 * @param conn</span><br><span class="line">	 * @param st</span><br><span class="line">	 * @param rs</span><br><span class="line">	 */</span><br><span class="line">	public static void release(Connection conn , Statement st , ResultSet rs)&#123;</span><br><span class="line">		closeRs(rs);</span><br><span class="line">		closeSt(st);</span><br><span class="line">		closeConn(conn);</span><br><span class="line">	&#125;</span><br><span class="line">	public static void release(Connection conn , Statement st)&#123;</span><br><span class="line">		closeSt(st);</span><br><span class="line">		closeConn(conn);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	</span><br><span class="line">	private static void closeRs(ResultSet rs)&#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			if(rs != null)&#123;</span><br><span class="line">				rs.close();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;finally&#123;</span><br><span class="line">			rs = null;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	private static void closeSt(Statement st)&#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			if(st != null)&#123;</span><br><span class="line">				st.close();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;finally&#123;</span><br><span class="line">			st = null;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	private static void closeConn(Connection conn)&#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			if(conn != null)&#123;</span><br><span class="line">				conn.close();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125; catch (SQLException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;finally&#123;</span><br><span class="line">			conn = null;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.util;</span><br><span class="line"></span><br><span class="line">public class TextUtils &#123;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 判断某一个字符串是否为空。</span><br><span class="line">	 * </span><br><span class="line">	 * @param s</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	public static boolean isEmpty(CharSequence s) &#123;</span><br><span class="line">		return s == null || s.length() == 0;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">	pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;添加学生页面&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">	&lt;form method=&quot;post&quot; action=&quot;AddServlet&quot;&gt;</span><br><span class="line">		&lt;table border=&quot;1&quot; width=&quot;600&quot;&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;姓名&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;sname&quot;&gt;&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;性别&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;男&quot;&gt;男 &lt;input</span><br><span class="line">					type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;女&quot;&gt;女&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;电话&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;phone&quot;&gt;&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;生日&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;birthday&quot;&gt;&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;爱好&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;游泳&quot;&gt;游泳 &lt;input</span><br><span class="line">					type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;篮球&quot;&gt;篮球 &lt;input</span><br><span class="line">					type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;足球&quot;&gt;足球 &lt;input</span><br><span class="line">					type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;看书&quot;&gt;看书 &lt;input</span><br><span class="line">					type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;写字&quot;&gt;写字&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td&gt;简介&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;&lt;textarea name=&quot;info&quot; rows=&quot;3&quot; cols=&quot;20&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;添加&quot;&gt;&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">		&lt;/table&gt;</span><br><span class="line">	&lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">    </span><br><span class="line"> &lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;</span><br><span class="line"> &lt;%@ taglib prefix=&quot;fn&quot; uri=&quot;http://java.sun.com/jsp/jstl/functions&quot; %&gt;</span><br><span class="line"> </span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;更新学生页面&lt;/title&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&lt;body&gt;</span><br><span class="line"></span><br><span class="line">&lt;h3&gt;更新学生页面&lt;/h3&gt;</span><br><span class="line"></span><br><span class="line">&lt;form method=&quot;post&quot; action=&quot;UpdateServlet&quot;&gt;</span><br><span class="line">	&lt;input type=&quot;hidden&quot; name=&quot;sid&quot; value=&quot;$&#123;stu.sid &#125;&quot;&gt;</span><br><span class="line">  &lt;table border=&quot;1&quot; width=&quot;600&quot;&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;姓名&lt;/td&gt;</span><br><span class="line">	&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;sname&quot; value=&quot;$&#123;stu.sname &#125;&quot;&gt;&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;性别&lt;/td&gt;</span><br><span class="line">	&lt;td&gt;</span><br><span class="line">		&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;男&quot; &lt;c:if test=&quot;$&#123;stu.gender == &apos;男&apos;&#125;&quot;&gt;checked&lt;/c:if&gt;&gt;男</span><br><span class="line">		&lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;女&quot; &lt;c:if test=&quot;$&#123;stu.gender == &apos;女&apos;&#125;&quot;&gt;checked&lt;/c:if&gt;&gt;女</span><br><span class="line">	&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;电话&lt;/td&gt;</span><br><span class="line">	&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;phone&quot; value=&quot;$&#123;stu.phone &#125;&quot;&gt;&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;生日&lt;/td&gt;</span><br><span class="line">	&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;birthday&quot; value=&quot;$&#123;stu.birthday &#125;&quot;&gt;&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;爱好&lt;/td&gt;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	&lt;td&gt;</span><br><span class="line">		&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;游泳&quot; &lt;c:if test=&quot;$&#123;fn:contains(stu.hobby,&apos;游泳&apos;) &#125;&quot;&gt;checked&lt;/c:if&gt;&gt;游泳</span><br><span class="line">		&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;篮球&quot; &lt;c:if test=&quot;$&#123;fn:contains(stu.hobby,&apos;篮球&apos;) &#125;&quot;&gt;checked&lt;/c:if&gt;&gt;篮球</span><br><span class="line">		&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;足球&quot; &lt;c:if test=&quot;$&#123;fn:contains(stu.hobby,&apos;足球&apos;) &#125;&quot;&gt;checked&lt;/c:if&gt;&gt;足球</span><br><span class="line">		&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;看书&quot; &lt;c:if test=&quot;$&#123;fn:contains(stu.hobby,&apos;看书&apos;) &#125;&quot;&gt;checked&lt;/c:if&gt;&gt;看书</span><br><span class="line">		&lt;input type=&quot;checkbox&quot; name=&quot;hobby&quot; value=&quot;写字&quot; &lt;c:if test=&quot;$&#123;fn:contains(stu.hobby,&apos;写字&apos;) &#125;&quot;&gt;checked&lt;/c:if&gt;&gt;写字</span><br><span class="line">	</span><br><span class="line">	&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td&gt;简介&lt;/td&gt;</span><br><span class="line">	&lt;td&gt;&lt;textarea name=&quot;info&quot; rows=&quot;3&quot; cols=&quot;20&quot;&gt;$&#123;stu.info &#125;&lt;/textarea&gt;&lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;tr&gt;</span><br><span class="line">	&lt;td colspan=&quot;2&quot;&gt; &lt;input type=&quot;submit&quot; value=&quot;更新&quot;&gt; &lt;/td&gt;</span><br><span class="line">  &lt;/tr&gt;</span><br><span class="line">  &lt;/table&gt;</span><br><span class="line">   &lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;首页&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line"></span><br><span class="line">&lt;h3&gt;&lt;a href=&quot;StudentListServlet&quot;&gt;显示所有学生列表&lt;/a&gt;&lt;/h3&gt;&lt;br&gt;</span><br><span class="line">&lt;h3&gt;&lt;a href=&quot;StudentListPageServlet?currentPage=1&quot;&gt;分页显示所有学生&lt;/a&gt;&lt;/h3&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">    </span><br><span class="line"> &lt;%@ taglib prefix=&quot;c&quot;  uri=&quot;http://java.sun.com/jsp/jstl/core&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;学生列表页面&lt;/title&gt;</span><br><span class="line"></span><br><span class="line">&lt;script type=&quot;text/javascript&quot;&gt;</span><br><span class="line"></span><br><span class="line">	function doDelete(sid) &#123;</span><br><span class="line">		// 弹出对话框，点击确定，请求Servlet</span><br><span class="line">		var flag = confirm(&quot;是否确定删除?&quot;);</span><br><span class="line">		if(flag)&#123;</span><br><span class="line">			//访问servlet</span><br><span class="line">			//window.location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">			location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">	&lt;form action=&quot;SearchStudentServlet&quot; method=&quot;post&quot;&gt;</span><br><span class="line">		&lt;table border=&quot;1&quot; width=&quot;700&quot;&gt;</span><br><span class="line">		</span><br><span class="line">			&lt;tr &gt;</span><br><span class="line">				&lt;td colspan=&quot;8&quot;&gt;</span><br><span class="line">					</span><br><span class="line">					按姓名查询:&lt;input type=&quot;text&quot; name=&quot;sname&quot;/&gt;</span><br><span class="line">					&amp;nbsp;</span><br><span class="line">					按性别查询:&lt;select name=&quot;sgender&quot;&gt;</span><br><span class="line">								&lt;option value=&quot;&quot;&gt;--请选择--</span><br><span class="line">								&lt;option value=&quot;男&quot;&gt;男</span><br><span class="line">								&lt;option value=&quot;女&quot;&gt;女</span><br><span class="line">							  &lt;/select&gt;</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">					&lt;input type=&quot;submit&quot; value=&quot;查询&quot;&gt;</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp;</span><br><span class="line">					&lt;a href=&quot;add.jsp&quot;&gt;添加&lt;/a&gt;</span><br><span class="line">				&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">		</span><br><span class="line">		  &lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">			&lt;td&gt;编号&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;姓名&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;性别&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;电话&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;生日&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;爱好&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;简介&lt;/td&gt;</span><br><span class="line">			&lt;td&gt;操作&lt;/td&gt;</span><br><span class="line">		  &lt;/tr&gt;</span><br><span class="line">		  </span><br><span class="line">			  &lt;c:forEach items=&quot;$&#123;list &#125;&quot; var=&quot;stu&quot;&gt;</span><br><span class="line">				  &lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sid &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sname &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.gender &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.phone &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.birthday &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.hobby &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.info &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;&lt;a href=&quot;EditServlet?sid=$&#123;stu.sid &#125;&quot;&gt;更新&lt;/a&gt;   &lt;a href=&quot;#&quot; onclick=&quot;doDelete($&#123;stu.sid&#125;)&quot;&gt;删除&lt;/a&gt;&lt;/td&gt;</span><br><span class="line">				  &lt;/tr&gt;</span><br><span class="line">			  &lt;/c:forEach&gt;</span><br><span class="line">		  &lt;/table&gt;</span><br><span class="line">	  &lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">	pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line"></span><br><span class="line">&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;学生列表页面&lt;/title&gt;</span><br><span class="line"></span><br><span class="line">&lt;script type=&quot;text/javascript&quot;&gt;</span><br><span class="line"></span><br><span class="line">	function doDelete(sid) &#123;</span><br><span class="line">		// 弹出对话框，点击确定，请求Servlet</span><br><span class="line">		var flag = confirm(&quot;是否确定删除?&quot;);</span><br><span class="line">		if(flag)&#123;</span><br><span class="line">			//访问servlet</span><br><span class="line">			//window.location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">			location.href=&quot;DeleteServlet?sid=&quot;+sid;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">	&lt;form action=&quot;SearchStudentServlet&quot; method=&quot;post&quot;&gt;</span><br><span class="line">		&lt;table border=&quot;1&quot; width=&quot;700&quot;&gt;</span><br><span class="line"></span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td colspan=&quot;8&quot;&gt;按姓名查询:&lt;input type=&quot;text&quot; name=&quot;sname&quot; /&gt; &amp;nbsp;</span><br><span class="line">					按性别查询:&lt;select name=&quot;sgender&quot;&gt;</span><br><span class="line">						&lt;option value=&quot;&quot;&gt;--请选择--</span><br><span class="line">						&lt;option value=&quot;男&quot;&gt;男</span><br><span class="line">						&lt;option value=&quot;女&quot;&gt;女</span><br><span class="line">				&lt;/select&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;input type=&quot;submit&quot; value=&quot;查询&quot;&gt;</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;add.jsp&quot;&gt;添加&lt;/a&gt;</span><br><span class="line">				&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line"></span><br><span class="line">			&lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">				&lt;td&gt;编号&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;姓名&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;性别&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;电话&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;生日&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;爱好&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;简介&lt;/td&gt;</span><br><span class="line">				&lt;td&gt;操作&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line"></span><br><span class="line">			&lt;c:forEach items=&quot;$&#123;pageBean.list &#125;&quot; var=&quot;stu&quot;&gt;</span><br><span class="line">				&lt;tr align=&quot;center&quot;&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sid &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.sname &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.gender &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.phone &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.birthday &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.hobby &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;$&#123;stu.info &#125;&lt;/td&gt;</span><br><span class="line">					&lt;td&gt;&lt;a href=&quot;EditServlet?sid=$&#123;stu.sid &#125;&quot;&gt;更新&lt;/a&gt; &lt;a href=&quot;#&quot;</span><br><span class="line">						onclick=&quot;doDelete($&#123;stu.sid&#125;)&quot;&gt;删除&lt;/a&gt;&lt;/td&gt;</span><br><span class="line">				&lt;/tr&gt;</span><br><span class="line">			&lt;/c:forEach&gt;</span><br><span class="line"></span><br><span class="line">			&lt;tr&gt;</span><br><span class="line">				&lt;td colspan=&quot;8&quot;&gt;第 $&#123;pageBean.currentPage &#125; /</span><br><span class="line">					$&#123;pageBean.totalPage &#125; &amp;nbsp;&amp;nbsp; 每页显示$&#123;pageBean.pageSize &#125;条</span><br><span class="line">					&amp;nbsp;&amp;nbsp;&amp;nbsp; 总的记录数$&#123;pageBean.totalSize &#125; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;c:if</span><br><span class="line">						test=&quot;$&#123;pageBean.currentPage !=1 &#125;&quot;&gt;</span><br><span class="line">						&lt;a href=&quot;StudentListPageServlet?currentPage=1&quot;&gt;首页&lt;/a&gt;</span><br><span class="line">						| &lt;a</span><br><span class="line">							href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.currentPage-1 &#125;&quot;&gt;上一页&lt;/a&gt;</span><br><span class="line">					&lt;/c:if&gt; &lt;c:forEach begin=&quot;1&quot; end=&quot;$&#123;pageBean.totalPage &#125;&quot; var=&quot;i&quot;&gt;</span><br><span class="line">						&lt;c:if test=&quot;$&#123;pageBean.currentPage == i &#125;&quot;&gt;</span><br><span class="line">			  				$&#123;i &#125;</span><br><span class="line">			  			&lt;/c:if&gt;</span><br><span class="line">						&lt;c:if test=&quot;$&#123;pageBean.currentPage != i &#125;&quot;&gt;</span><br><span class="line">							&lt;a href=&quot;StudentListPageServlet?currentPage=$&#123;i &#125;&quot;&gt;$&#123;i &#125;&lt;/a&gt;</span><br><span class="line">						&lt;/c:if&gt;</span><br><span class="line"></span><br><span class="line">					&lt;/c:forEach&gt; &lt;c:if test=&quot;$&#123;pageBean.currentPage !=pageBean.totalPage &#125;&quot;&gt;</span><br><span class="line">						&lt;a</span><br><span class="line">							href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.currentPage+1 &#125;&quot;&gt;下一页&lt;/a&gt; | </span><br><span class="line">			  			&lt;a</span><br><span class="line">							href=&quot;StudentListPageServlet?currentPage=$&#123;pageBean.totalPage &#125;&quot;&gt;尾页&lt;/a&gt;</span><br><span class="line">					&lt;/c:if&gt;</span><br><span class="line">				&lt;/td&gt;</span><br><span class="line">			&lt;/tr&gt;</span><br><span class="line">		&lt;/table&gt;</span><br><span class="line">	&lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/11158618-a77a8b8e2cca3311.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line">package com.dashucoding.service.impl;</span><br><span class="line"></span><br><span class="line">import java.sql.SQLException;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.dashucoding.dao.StudentDao;</span><br><span class="line">import com.dashucoding.dao.impl.StudentDaoImpl;</span><br><span class="line">import com.dashucoding.domain.PageBean;</span><br><span class="line">import com.dashucoding.domain.Student;</span><br><span class="line">import com.dashucoding.service.StudentService;</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 这是学生业务实现</span><br><span class="line"> * */</span><br><span class="line">public class StudentServiceImpl implements StudentService &#123;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; findAll() throws SQLException &#123;</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findAll();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void insert(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.insert(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void delete(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.delete(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public Student findStudentById(int sid) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.findStudentById(sid);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public void update(Student student) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		dao.update(student);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;Student&gt; searchStudent(String sname, String sgender) throws SQLException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		return dao.searchStudent(sname, sgender);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public PageBean findStudentByPage(int currentPage) throws SQLException &#123;</span><br><span class="line"></span><br><span class="line">		// 封装分页的该页数据</span><br><span class="line">		PageBean&lt;Student&gt; pageBean = new PageBean&lt;Student&gt;();</span><br><span class="line"></span><br><span class="line">		int pageSize = StudentDao.PAGE_SIZE;</span><br><span class="line">		pageBean.setCurrentPage(currentPage); </span><br><span class="line">		// 设置当前页</span><br><span class="line">		pageBean.setPageSize(pageSize); </span><br><span class="line">		// 设置每页显示多少记录</span><br><span class="line"></span><br><span class="line">		StudentDao dao = new StudentDaoImpl();</span><br><span class="line">		List&lt;Student&gt; list = dao.findStudentByPage(currentPage);</span><br><span class="line">		pageBean.setList(list); </span><br><span class="line">		// 设置这一页的学生数据</span><br><span class="line"></span><br><span class="line">		// 总的记录数， 总的页数。</span><br><span class="line">		int count = dao.findCount();</span><br><span class="line">		pageBean.setTotalSize(count); </span><br><span class="line">		// 设置总的记录数</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1); // 总页数</span><br><span class="line">		return pageBean;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="结言"><a href="#结言" class="headerlink" title="结言"></a>结言</h2><p>好了，欢迎在留言区留言，与大家分享你的经验和心得。</p>
<p>感谢你学习今天的内容，如果你觉得这篇文章对你有帮助的话，也欢迎把它分享给更多的朋友，感谢。</p>
<blockquote>
<p>达叔小生：往后余生，唯独有你<br>You and me, we are family !<br>90后帅气小伙，良好的开发习惯；独立思考的能力；主动并且善于沟通<br>简书博客： 达叔小生<br><a href="https://www.jianshu.com/u/c785ece603d1" target="_blank" rel="noopener">https://www.jianshu.com/u/c785ece603d1</a></p>
</blockquote>
<h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><ul>
<li>下面我将继续对 其他知识 深入讲解 ，有兴趣可以继续关注</li>
<li>小礼物走一走 or 点赞</li>
</ul>
      
    </div>
    
    
    

      <div>
        
          <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
        
      </div>

    

      <div>
        <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/微信公众号.jpg" alt="达叔小生 wechat" style="width: 200px; max-width: 100%">
    <div>欢迎您扫一扫上面的微信公众号，订阅我的博客！</div>
</div>

      </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="达叔小生 微信支付">
        <p>微信支付</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    达叔小生
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://huangguangda.github.io/2019/02/02/1/" title="第83节：Java中的学生管理系统分页功能">https://huangguangda.github.io/2019/02/02/1/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/带你学会Java基础课程/" rel="tag"><i class="fa fa-tag"></i> 带你学会Java基础课程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/02/01/1/" rel="next" title="第82节：Java中的学生管理系统">
                <i class="fa fa-chevron-left"></i> 第82节：Java中的学生管理系统
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/02/03/1/" rel="prev" title="第84节：Java中的网络编程（中）">
                第84节：Java中的网络编程（中） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNTU5OC8xMjEzNA=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.gif" alt="达叔小生">
            
              <p class="site-author-name" itemprop="name">达叔小生</p>
              <p class="site-description motion-element" itemprop="description"></p>

            <div id="days"></div>
<script>
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("04/23/1997 00:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">94</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">20</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
                <a title="收藏到书签，偶尔High一下^_^" rel="alternate" class="mw-harlem_shake_slow wobble shake" href="javascript:(function() {
    function c() {
        var e = document.createElement(&quot;link&quot;);
        e.setAttribute(&quot;type&quot;, &quot;text/css&quot;);
        e.setAttribute(&quot;rel&quot;, &quot;stylesheet&quot;);
        e.setAttribute(&quot;href&quot;, f);
        e.setAttribute(&quot;class&quot;, l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement(&quot;div&quot;);
        e.setAttribute(&quot;class&quot;, a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement(&quot;audio&quot;);
        e.setAttribute(&quot;class&quot;, l);
        e.src = i;
        e.loop = false;
        e.addEventListener(&quot;canplay&quot;, function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener(&quot;ended&quot;, function() {
            N();
            h()
        }, true);
        e.innerHTML = &quot; <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>&quot;;
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += &quot; &quot; + s + &quot; &quot; + o
    }
 
    function T(e) {
        e.className += &quot; &quot; + s + &quot; &quot; + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp(&quot;\\b&quot; + s + &quot;\\b&quot;);
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, &quot;&quot;)
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = &quot;//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3&quot;;
    var s = &quot;mw-harlem_shake_me&quot;;
    var o = &quot;im_first&quot;;
    var u = [&quot;im_drunk&quot;, &quot;im_baked&quot;, &quot;im_trippin&quot;, &quot;im_blown&quot;];
    var a = &quot;mw-strobe_light&quot;;
    var f = &quot;//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css&quot;;
    var l = &quot;mw_added_css&quot;;
    var b = g();
    var w = y();
    var C = document.getElementsByTagName(&quot;*&quot;);
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn(&quot;Could not find a node of the right size. Please try a different page.&quot;);
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()"><i class="fa fa-music"></i> High</a>

            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/huangguangda" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:2397923107@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/c785ece603d1" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-android"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_36232611" target="_blank" title="csdn">
                      
                        <i class="fa fa-fw fa-spinner"></i>csdn</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.douban.com/people/186539024/" target="_blank" title="豆瓣">
                      
                        <i class="fa fa-fw fa-bath"></i>豆瓣</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/da-shu-xiao-sheng/activities" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/5a16e1f3f265da43128096cb" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-google"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/5507262458/profile?topnav=1&wvr=6" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI1NTcxOTQ1Nw==&scene=124#wechat_redirect" target="_blank" title="历史">
                      
                        <i class="fa fa-fw fa-apple"></i>历史</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.cnblogs.com/dashucoding/" target="_blank" title="博客园">
                      
                        <i class="fa fa-fw fa-facebook"></i>博客园</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gdone.gitee.io/englishpages/index.html" target="_blank" title="英文简历">
                      
                        <i class="fa fa-fw fa-globe"></i>英文简历</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gdone.gitee.io/pages/" target="_blank" title="中文简历">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>中文简历</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/GDone/events" target="_blank" title="码云">
                      
                        <i class="fa fa-fw fa-twitter"></i>码云</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://my.oschina.net/xiaomaomi1997/" target="_blank" title="开源中国">
                      
                        <i class="fa fa-fw fa-facebook"></i>开源中国</a>
                  </span>
                
            </div>
          

          
          
            <div class="cc-license motion-element" itemprop="license">
              <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
                <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons">
              </a>
            </div>
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa fa-fw fa-globe"></i>
                推荐阅读
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.alloyteam.com/nav/" title="Web前端导航" target="_blank">Web前端导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.36zhen.com/t?id=3448" title="前端书籍资料" target="_blank">前端书籍资料</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ife.baidu.com/" title="百度前端技术学院" target="_blank">百度前端技术学院</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://wf.uisdc.com/cn/" title="google前端开发基础" target="_blank">google前端开发基础</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.geekbang.org/" title="极客邦科技" target="_blank">极客邦科技</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ilxdh.com/" title="龙轩导航" target="_blank">龙轩导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://code.giffox.com/" title="程序员导航" target="_blank">程序员导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://search.chongbuluo.com/" title="快搜" target="_blank">快搜</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.android-doc.com/training/index.html" title="Android中文API" target="_blank">Android中文API</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://developer.android.google.cn/" title="Android Developers" target="_blank">Android Developers</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.freecodecamp.cn/" title="FreeCodeCamp中文社区" target="_blank">FreeCodeCamp中文社区</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://docs.oracle.com/javase/specs/" title="Java SE规范" target="_blank">Java SE规范</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://liuwangshu.cn/" title="刘望舒" target="_blank">刘望舒</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.colabug.com/author/3159ee71c93b3b4a/" title="小楼昨夜又秋风" target="_blank">小楼昨夜又秋风</a>
                  </li>
                
              </ul>

            </div>
          


        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#结言"><span class="nav-number">1.</span> <span class="nav-text">结言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结语"><span class="nav-number">2.</span> <span class="nav-text">结语</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="heart">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">达叔小生</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">357.6k</span>
  
</div>






  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共357.6k字</span>
</div>

<div class="weixin-box">
  <div class="weixin-menu">
    <div class="weixin-hover">
      <div class="weixin-description">微信扫一扫，订阅本博客</div>
    </div>
  </div>
</div>
        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客数</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>





  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=65809965";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  


  <script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script>
<script type="text/javascript" src="/js/src/custom.js"></script>


   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none"></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/src/fireworks.js"></script>


  <!-- 代码块复制功能 -->
  <script type="text/javascript" src="/js/src/clipboard.min.js"></script>  
  <script type="text/javascript" src="/js/src/clipboard-use.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"live2d-widget-model-hibiki"},"display":{"position":"right","width":75,"height":150},"mobile":{"show":false},"log":false});</script></body>
</html>